//
//  FirstRootTableViewCell.m
//  结伴
//
//  Created by eliot on 16/8/8.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "FirstRootTableViewCell.h"

@interface FirstRootTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconIV;

@property (weak, nonatomic) IBOutlet UIImageView *sexIV;

@property (weak, nonatomic) IBOutlet UILabel *nameLb;

@property (weak, nonatomic) IBOutlet UILabel *timeLb;

@property (weak, nonatomic) IBOutlet UILabel *contetLb;

@property (weak, nonatomic) IBOutlet UIView *detailView;

@property (weak, nonatomic) IBOutlet UILabel *fromAddress;

@property (weak, nonatomic) IBOutlet UILabel *destinationLb;

@property (weak, nonatomic) IBOutlet UILabel *durationLb;

@property (weak, nonatomic) IBOutlet UILabel *ticketLb;

@property (weak, nonatomic) IBOutlet UILabel *oudoorLb;

@property (weak, nonatomic) IBOutlet UILabel *happyLb;

@property (weak, nonatomic) IBOutlet UILabel *personCountLb;

@property (weak, nonatomic) IBOutlet UIScrollView *myScrollerView;

@property (weak, nonatomic) IBOutlet UILabel *locateAddressLb;

@property (weak, nonatomic) IBOutlet UILabel *pointCountLb;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentLbH;



@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scTop;





@end


@implementation FirstRootTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.iconIV.layer.cornerRadius = 20;
    self.iconIV.layer.masksToBounds = YES;

    self.nameLb.textColor = ThreeColor;
    self.timeLb.textColor = nineColor;
    self.contetLb.textColor = zeroColor;
    self.locateAddressLb.textColor = nineColor;
    self.pointCountLb.textColor = nineColor;
    self.ticketLb.backgroundColor = bbdColor;
    self.oudoorLb.backgroundColor = bbdColor;
    self.happyLb.backgroundColor = bbdColor;
    self.personCountLb.backgroundColor = bbdColor;
    
    
    self.ticketLb.layer.cornerRadius = 6;
    self.ticketLb.layer.masksToBounds = YES;
    self.oudoorLb.layer.cornerRadius = 6;
    self.oudoorLb.layer.masksToBounds = YES;
    self.happyLb.layer.cornerRadius = 6;
    self.happyLb.layer.masksToBounds = YES;
    self.personCountLb.layer.cornerRadius = 6;
    self.personCountLb.layer.masksToBounds = YES;
    
    
    [self setupLineSpacing];
}

//设置label的行间距
- (void)setupLineSpacing {
   
    NSString * cLabelString = @"这是测试UILabel行间距的text。这是测试UILabel行间距的text。\n 这是测试UILabel行间距的text。\n 这是测试UILabel行间距的text。这是测试UILabel行间距的text。这是测试UILabel行间距的text。这是测试UILabel行间距的text。";
    self.contetLb.numberOfLines = 0;
    self.contetLb.font = [UIFont systemFontOfSize:15];
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:cLabelString];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [cLabelString length])];
    [attributedString1 addAttribute:NSFontAttributeName
     
                    value:[UIFont systemFontOfSize:14.0]
     
                    range:NSMakeRange(0, [cLabelString length])];
    
    
    [self.contetLb setAttributedText:attributedString1];
    [self.contetLb sizeToFit];

    
    CGFloat wid=Swidth - 26;
    CGSize siz=CGSizeMake(wid, MAXFLOAT);
    
    CGRect rr = [attributedString1 boundingRectWithSize:siz options:NSStringDrawingUsesLineFragmentOrigin context:nil];
    
    self.contentLbH.constant = rr.size.height;
    
    NSLog(@"%f, %@", self.contentLbH.constant, attributedString1);

}

- (void)setModel:(FirstRootViewVCModel *)model
{
    _model = model;
    [UIView animateWithDuration:0.25 animations:^{
        if (_model.isOpen) {
            self.fromAddress.hidden = NO;
            self.destinationLb.hidden = NO;
            self.durationLb.hidden = NO;
            self.ticketLb.hidden = NO;
            self.oudoorLb.hidden = NO;
            self.happyLb.hidden = NO;
            self.personCountLb.hidden = NO;
            //self.detailViewH.constant = 154;
            
        }else {
            
            
            self.fromAddress.hidden = YES;
            self.destinationLb.hidden = YES;
            self.durationLb.hidden = YES;
            self.ticketLb.hidden = YES;
            self.oudoorLb.hidden = YES;
            self.happyLb.hidden = YES;
            self.personCountLb.hidden = YES;
           // self.detailViewH.constant = 0;
        }
    }];
   
}


/**点击  张开按钮*/
- (IBAction)clickExpansionExpansionclickExtentionBtn:(UIButton *)sender {
    
    _model.isOpen = !_model.isOpen;
    self.extentionBlock(_model.isOpen);
    NSLog(@"%d", _model.isOpen);
    
}




/**
 在宽度一定的情况下返回一个适合的高度
 */
- (CGFloat)textSizeH:(NSString *)text WithWidth:(CGFloat)width WithFount:(UIFont *)fount
{
    
    if(fount == nil){
        fount = [UIFont systemFontOfSize:[UIFont systemFontSize]];
    }
    return [text sizeWithFont:fount constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:0].height;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
